<?php echo $html->script(array("jquery.form.js", "jquery.validate.js",
    "jquery.pagination.js", "jquery.tablesorter.min.js", "jquery.tablednd.js", "datepicker.js")); ?>
<?php
echo $this->Html->css('datepicker');
?>
<script type="text/javascript">
    // <![CDATA[
    function pad(value, length) {
        length = length || 2;
        return "0000".substr(0,length - Math.min(String(value).length, length)) + value;
    };
    // ]]>
</script>
<style type="text/css">

    td table td {
        background: none repeat scroll 0 0 #FFFFFF;
        border-bottom: 0px;
        border-right: 0px;
        color: #000;
        font-size: 12px;
    }
</style>
<div id="sub_nav">
    <p>Quick Links:</p>
    <ul>
        <li>
            <?php if ($session->read('grouptype') == 'S-Admins') { ?>
                <a href="javascript:void(0);" controller="users" action="add_superadmin"
                   title="Add"
                   onclick='showPop(this)'>Add New Super-Admin</a>
                   <?php
               }
               ?>
        </li>
    </ul>
</div>
<div class="breadcrumb">
    <ul id="breadcrumb">
        <li><a href="<?php echo Configure::read('base_url'); ?>backstage" title="Home">
                <?php echo $this->Html->image("home.png", array("alt" => "Home", 'class' => 'home', 'border' => '0')); ?>
            </a></li>
        <li><a href="<?php echo Configure::read('base_url'); ?>backstage/users/editqadmin" title="My Information">My Information</a></li>

    </ul>
</div>
<?php echo $this->element('admin/admin_leftmenu'); ?>
<div id="left">
    <?php
    echo $this->Session->flash();
    if ($this->Session->check('Message.auth'))
        echo $this->Session->flash('auth');
    ?>
    <div class="div_header"><?php __('My Information'); ?></div>
    <div class="div_content">
        <form method="post" id="edit_admin" action="<?php echo Configure::read('base_url') . "backstage/users/editqadmin"; ?>">
            <table cellspacing="0" id="mytable" style="border: 0px;">
                <tbody>
                    <tr >
                        <td colspan="2">
                            <table width="100%" border="0" cellspacing="0" cellpadding="3" style="border: 0px;">
                                <tr style="border: 0px;">
                                    <td width="266" style="border: 0px;" class="tdtext">
                                        First Name*
                                    </td>
                                    <td width="247">
                                        <?php
                                        echo $this->Form->hidden('User.id');
                                        echo $this->Form->input('User.first_name', array('label' => false, 'div' => false, 'class' => 'required'));
                                        ?>
                                    </td>
                                    <td width="266" align="right" class="tdtext">
                                        Last Name*
                                    </td>
                                    <td width="247">
                                        <?php
                                        echo $this->Form->input('User.last_name', array('label' => false, 'div' => false, 'class' => 'required'));
                                        ?>
                                    </td>
                                </tr>
                                <tr >
                                    <td width="266" class="tdtext">
                                        Street Address*
                                    </td>
                                    <td width="247" colspan="3">
                                        <?php
                                        echo $this->Form->input('User.address', array('label' => false, 'div' => false, 'class' => 'required medium'));
                                        ?>
                                    </td>

                                </tr>
                                <tr >
                                    <td width="266">

                                    </td>
                                    <td width="247" colspan="3">
                                        <?php
                                        echo $this->Form->input('User.address2', array('label' => false, 'div' => false, 'class' => 'medium'));
                                        ?>
                                    </td>

                                </tr>
                                <tr >
                                    <td width="266" class="tdtext">
                                        City*
                                    </td>
                                    <td width="247" colspan="3"><div id="userCityIdWrapper">
                                            <?php
                                            echo $this->Form->input('User.city_id', array('label' => false, 'div' => false, 'class' => 'required', 'selected' => $this->data['User']['city_id']));
                                            ?></div>
                                    </td>

                                </tr>
                                <tr>
                                    <td width="266" class="tdtext">
                                        State*
                                    </td>
                                    <td width="247"><div id="userStateIdWrapper">
                                            <?php
                                            echo $this->Form->input('User.state_id', array('label' => false, 'div' => false, 'class' => 'required', 'selected' => $this->data['User']['state_id']));
                                            ?></div>
                                    </td>
                                    <td width="266" align="right" class="tdtext">
                                        Zip*
                                    </td>
                                    <td width="247">
                                        <?php
                                        echo $this->Form->input('User.zip', array('label' => false, 'div' => false, 'class' => 'required'));
                                        ?>
                                    </td>
                                </tr>
                                <tr >
                                    <td width="266" class="tdtext">
                                        Country*
                                    </td>
                                    <td width="247" colspan="3">
                                        <?php
                                        echo $this->Form->input('User.country_id', array('label' => false, 'div' => false, 'class' => 'required', 'selected' => $this->data['User']['country_id']));
                                        ?>
                                    </td>

                                </tr>
                                <tr >
                                    <td width="266" class="tdtext">
                                        Primary Phone # *
                                    </td>
                                    <td width="247" colspan="3">
                                        <?php
                                        echo $this->Form->input('User.primary_phone', array('label' => false, 'div' => false, 'maxlength' => "3", 'size' => '4', 'style' => 'float:left;margin-right:10px;'));
                                        echo $this->Form->input('User.phone2', array('label' => false, 'div' => false, 'maxlength' => "4", 'size' => '5', 'style' => 'float:left;margin-right:10px;'));
                                        echo $this->Form->input('User.phone3', array('label' => false, 'div' => false, 'maxlength' => "3", 'size' => '4', 'class' => 'required'));
                                        ?>
                                    </td>

                                </tr>
                                <tr>
                                    <td width="266" class="tdtext">
                                        Email*
                                    </td>
                                    <td width="247">
                                        <?php
                                        echo $this->Form->input('User.email', array('id' => 'email', 'label' => false,
                                            'div' => false, 'class' => 'required email'));
                                        ?>
                                    </td>
                                    <td width="266" align="right" class="tdtext">
                                        Confirm Email*
                                    </td>
                                    <td width="247">
                                        <?php
                                        echo $this->Form->input('cemail', array('label' => false, 'name' => 'cemail',
                                            'div' => false, 'size' => '19', 'value' => $this->data['User']['email']));
                                        ?>
                                    </td>
                                </tr>
                                <tr >
                                    <td width="266" align="right">
                                        User Id*
                                    </td>
                                    <td width="247" colspan="3">
                                        <input type="text" disabled name="nothing"
                                               value="<?php echo $this->data['User']['username']; ?>"/>
                                               <?php
                                               /* echo $this->Form->input('User.username',array('label'=>false,'div'=>false,
                                                 'name'=>'username','id'=>'username')); */
                                               ?>
                                    </td>

                                </tr>
                                <tr>
                                    <td width="266" align="right">
                                        Password*
                                    </td>
                                    <td width="247">
                                        <?php
                                        echo $this->Form->input('password', array('label' => false, 'div' => false,
                                            'name' => 'password', 'id' => 'password', 'type' => 'password'));
                                        ?>
                                    </td>
                                    <td width="266" align="right">
                                        Confirm Password*
                                    </td>
                                    <td width="247">
                                        <?php
                                        echo $this->Form->input('cpassword', array('label' => false, 'div' => false,
                                            'name' => 'cpassword', 'id' => 'cpassword', 'type' => 'password', 'size' => '19'));
                                        ?>
                                    </td>
                                </tr>
                                <tr >
                                    <td width="266" class="tdtext">
                                        Secret Question*
                                    </td>
                                    <td width="247" colspan="3">
                                        <?php
                                        echo $this->Form->input('User.secretquestion_id', array('empty' => 'Select your Secret question', 'div' => false, 'label' => false, 'class' => 'required', 'style' => "width:195px"));
                                        ?>
                                    </td>

                                </tr>
                                <tr >
                                    <td width="266" class="tdtext">
                                        Your Secret Answer*
                                    </td>
                                    <td width="247" colspan="3">
                                        <?php
                                        echo $this->Form->input('User.ques_ans', array('label' => false, 'value' => base64_decode($this->data['User']['ques_ans']), 'div' => false, 'class' => 'required'));
                                        ?>
                                    </td>

                                </tr>
                                <tr >
                                    <td width="266" class="tdtext">
                                        Date of Birth*
                                    </td>
                                    <td width="247" colspan="3">
                                        <input type="text" readonly class="w16em required" id="selectDate"
                                               name="data[User][dateofbirth]"
                                               value="<?php echo $this->data['User']['dateofbirth']; ?>"/>
                                               <?php
                                               /* echo $this->Form->input('User.dateofbirth',array('label'=>false,'div'=>false,
                                                 'class'=>'required','minYear'=>1900)); */
                                               ?>
                                        <script type="text/javascript">
                                            var today     = new Date(),
                                            // low range, 35 days before today's date
                                            //rangeLow  = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 35),
                                            // low range, form today's date
                                            rangeLow  = new Date(today.getFullYear()-150, today.getMonth(), today.getDate()),
                                            // high range, one year after today's date
                                            rangeHigh = new Date(today.getFullYear()-18, today.getMonth(), today.getDate())

                                            var opts = {
                                                formElements:{"selectDate":"Y-ds-m-ds-d"},
                                                showWeeks:true,
                                                statusFormat:"l-cc-sp-d-sp-F-sp-Y",
                                                // Set some dynamically calculated ranges
                                                rangeLow:rangeLow.getFullYear() + "" + pad(rangeLow.getMonth()+1) + pad(rangeLow.getDate()),
                                                rangeHigh:rangeHigh.getFullYear() + "" + pad(rangeHigh.getMonth()+1) + pad(rangeHigh.getDate())

                                            };
                                            if(jQuery("#fd-selectDate").html()!=null){
                                                jQuery('#fd-selectDate').remove();
                                            }
                                            datePickerController.createDatePicker(opts);



                                            // <![CDATA[
                                            /* var opts = {
                                                        formElements:{"selectDate":"Y-ds-m-ds-d"},
                                                        showWeeks:true,
                                                        // Show a status bar and use the format "l-cc-sp-d-sp-F-sp-Y" (e.g. Friday, 25 September 2009)
                                                        statusFormat:"l-cc-sp-d-sp-F-sp-Y"
                                                };
                                                //alert(jQuery("#fd-selectDate").html());
                                                if(jQuery("#fd-selectDate").html()!=null){
                                                   jQuery('#fd-selectDate').remove();
                                                }
                                                datePickerController.createDatePicker(opts);*/
                                            // ]]>
                                        </script>
                                    </td>

                                </tr>
                                <tr>
                                    <td width="144">
                                    </td>
                                    <td width="347"><input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="button" id="button" value="Update" /></td>
                                    <td colspan="2"></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </tbody></table>
        </form>
    </div>
    <div class="div_bottom"></div>
</div>

<!-- edit sidebar items here -->

</div>
<script type="text/javascript">
    jQuery(document).ready(function(){
        //Populate City drop down on change State drop down
        jQuery("#UserStateId").live('change',function () {
            var stateId=jQuery(this).val();
            var URL="<?php echo Configure::read('base_url'); ?>users/loadCity/"+stateId;          
            jQuery("#UserCityId").html("<option value='0'>loading...</option>");
            jQuery("#userCityIdWrapper").load(URL);
        
        });
        //Populate State drop down on change Country dropdown
        jQuery("#UserCountryId").live('change',function () {
            var countryId=jQuery(this).val();
            var URL="<?php echo Configure::read('base_url'); ?>users/loadState/"+countryId;          
            jQuery("#UserStateId").html("<option value='0'>loading...</option>");
            jQuery("#userStateIdWrapper").load(URL);
        
        });
        var v = jQuery("#edit_admin").validate({
            rules: {
                email:{
                    'required':true,
                    'email':true
                },
                cemail: {
                    required: true,
                    equalTo: '#email'
                },
                cpassword: {
                    equalTo: '#password'
                }
            }

        });

    });
</script>